#include<bits/stdc++.h>
using namespace std;

struct node
{
	int x, y;
};

int a[100][100];
int dx[] = {0, -1, 1, 0, 0};
int dy[] = {0, 0, 0, -1, 1};

queue<node> q;

void bfs(int x, int y)
{
	q.push({x, y});
	a[x][y] = 0;
	while(!q.empty())
	{
		node t = q.front();
		q.pop();
		for(int i = 1;i <= 4;i++)
		{
			int xx = t.x+dx[i];
			int yy = t.y+dy[i];
			if(a[xx][yy])
			{
				q.push({xx, yy});
				a[xx][yy] = 0;
			}
		}
	}
}

int main()
{
	int n, m;
	char ch;
	cin>>n>>m;
	
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			cin>>ch;
			a[i][j] = ch-'0';
		}
	}
	
	int cnt = 0;
	
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(a[i][j])
			{
				bfs(i, j);
				cnt++;
			}
		}
	}
	cout<<cnt;
    return 0;
}

